<?php

namespace app\admin\model;

use think\Model;


class Chatmessages extends Model
{

    

    

    // 表名
    protected $name = 'chatmessages';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'message_type_text',
        'status_text'
    ];
    

    
    public function getMessageTypeList()
    {
        return ['text' => __('Text'), 'image' => __('Image'), 'video' => __('Video'), 'audio' => __('Audio'), 'file' => __('File'), 'location' => __('Location')];
    }

    public function getStatusList()
    {
        return ['sent' => __('Sent'), 'delivered' => __('Delivered'), 'failed' => __('Failed')];
    }


    public function getMessageTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['message_type']) ? $data['message_type'] : '');
        $list = $this->getMessageTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }




}
